package com.atguigu.rabbitmq.six;

import com.atguigu.rabbitmq.utils.RabbitMqUtils;
import com.rabbitmq.client.Channel;

import java.io.IOException;
import java.util.Scanner;
import java.util.concurrent.TimeoutException;

/*
* 该类负责发送，是发送端
* */
public class DirectLogs {

    /*交换机的名字*/
    public static final String EXCHANGE_NAME="direct_logs";

    public static void main(String[] args) throws IOException, TimeoutException {
        /*根据Connection得到一个信道*/
        Channel channel = RabbitMqUtils.getChannel();
        /*根据信道创建交换机*/
//        channel.exchangeDeclare(EXCHANGE_NAME, "fauout");
        /*输入数据*/
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()){
            String message = scanner.next();
            /*1.交换机名 2.routingKey/队列名称
              3.其他参数，比如可以写上消息的属性持久化，将消息保存到磁盘里面
              4.将消息转换为二进制
              */
            channel.basicPublish(EXCHANGE_NAME, "warning", null, message.getBytes("UTF-8"));
            System.out.println("生产者发出消息："+message);
        }
    }

}